<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: D:/Projects/MiXiM/extsrc/mixim/src/base/utils/FindModule.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00306.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">FindModule.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef FIND_MODULE_H</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define FIND_MODULE_H</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;omnetpp.h&gt;</span>
<a name="l00005"></a>00005 
<a name="l00012"></a>00012 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T = cModule * const &gt;
<a name="l00013"></a><a class="code" href="a00093.html">00013</a> <span class="keyword">class </span><a class="code" href="a00093.html" title="Provides method templates to find omnet modules.">FindModule</a>
<a name="l00014"></a>00014 {
<a name="l00015"></a>00015     <span class="keyword">public</span>:
<a name="l00022"></a><a class="code" href="a00093.html#a661c335281d62d8df4affc46cc4fff9f">00022</a>         <span class="keyword">static</span> T <a class="code" href="a00093.html#a661c335281d62d8df4affc46cc4fff9f" title="Returns a pointer to a sub module of the passed module with the type of this template.">findSubModule</a>(<span class="keyword">const</span> cModule * <span class="keyword">const</span> top)
<a name="l00023"></a>00023         {
<a name="l00024"></a>00024             <span class="keywordflow">for</span> (cModule::SubmoduleIterator i(top); !i.end(); i++)
<a name="l00025"></a>00025             {
<a name="l00026"></a>00026                 cModule * <span class="keyword">const</span> sub = i();
<a name="l00027"></a>00027                 <span class="comment">// this allows also a return type of read only pointer: const cModule *const</span>
<a name="l00028"></a>00028                 T dCastRet = <span class="keyword">dynamic_cast&lt;</span>T<span class="keyword">&gt;</span>(sub);
<a name="l00029"></a>00029                 <span class="keywordflow">if</span> (dCastRet != NULL)
<a name="l00030"></a>00030                     <span class="keywordflow">return</span> dCastRet;
<a name="l00031"></a>00031                 <span class="comment">// this allows also a return type of read only pointer: const cModule *const</span>
<a name="l00032"></a>00032                 T recFnd = <a class="code" href="a00093.html#a661c335281d62d8df4affc46cc4fff9f" title="Returns a pointer to a sub module of the passed module with the type of this template.">findSubModule</a>(sub);
<a name="l00033"></a>00033                 <span class="keywordflow">if</span> (recFnd != NULL)
<a name="l00034"></a>00034                     <span class="keywordflow">return</span> recFnd;
<a name="l00035"></a>00035             }
<a name="l00036"></a>00036             <span class="keywordflow">return</span> NULL;
<a name="l00037"></a>00037         }
<a name="l00038"></a>00038 
<a name="l00045"></a><a class="code" href="a00093.html#a36e4632a6c8c7dbdc177639957a8e62a">00045</a>         <span class="keyword">static</span> T <a class="code" href="a00093.html#a36e4632a6c8c7dbdc177639957a8e62a" title="Returns a pointer to the module with the type of this template.">findGlobalModule</a>()
<a name="l00046"></a>00046         {
<a name="l00047"></a>00047             <span class="keywordflow">return</span> <a class="code" href="a00093.html#a661c335281d62d8df4affc46cc4fff9f" title="Returns a pointer to a sub module of the passed module with the type of this template.">findSubModule</a>(simulation.getSystemModule());
<a name="l00048"></a>00048         }
<a name="l00049"></a>00049 
<a name="l00056"></a><a class="code" href="a00093.html#af74cf61bdeba8f88de8936dc32fc19ae">00056</a>         <span class="keyword">static</span> cModule* <a class="code" href="a00093.html#af74cf61bdeba8f88de8936dc32fc19ae" title="Returns a pointer to the host module of the passed module.">findHost</a>(cModule * <span class="keyword">const</span> m)
<a name="l00057"></a>00057         {
<a name="l00058"></a>00058             cModule* parent = m != NULL ? m-&gt;getParentModule() : NULL;
<a name="l00059"></a>00059             cModule* node = m;
<a name="l00060"></a>00060 
<a name="l00061"></a>00061             <span class="comment">// all nodes should be a sub module of the simulation which has no parent module!!!</span>
<a name="l00062"></a>00062             <span class="keywordflow">while</span> (parent != NULL &amp;&amp; parent-&gt;getParentModule() != NULL)
<a name="l00063"></a>00063             {
<a name="l00064"></a>00064                 node = parent;
<a name="l00065"></a>00065                 parent = node-&gt;getParentModule();
<a name="l00066"></a>00066             }
<a name="l00067"></a>00067             <span class="keywordflow">return</span> node;
<a name="l00068"></a>00068         }
<a name="l00069"></a>00069         <span class="keyword">static</span> cModule* findNetwork(cModule * <span class="keyword">const</span> m)
<a name="l00070"></a>00070         {
<a name="l00071"></a>00071             cModule* node = <a class="code" href="a00093.html#af74cf61bdeba8f88de8936dc32fc19ae" title="Returns a pointer to the host module of the passed module.">findHost</a>(m);
<a name="l00072"></a>00072 
<a name="l00073"></a>00073             <span class="keywordflow">return</span> node ? node-&gt;getParentModule() : node;
<a name="l00074"></a>00074         }
<a name="l00075"></a>00075         <span class="comment">// the constness version</span>
<a name="l00076"></a>00076         <span class="keyword">static</span> <span class="keyword">const</span> cModule* <a class="code" href="a00093.html#af74cf61bdeba8f88de8936dc32fc19ae" title="Returns a pointer to the host module of the passed module.">findHost</a>(<span class="keyword">const</span> cModule * <span class="keyword">const</span> m)
<a name="l00077"></a>00077         {
<a name="l00078"></a>00078             <span class="keyword">const</span> cModule* parent = m != NULL ? m-&gt;getParentModule() : NULL;
<a name="l00079"></a>00079             <span class="keyword">const</span> cModule *node = m;
<a name="l00080"></a>00080 
<a name="l00081"></a>00081             <span class="comment">// all nodes should be a sub module of the simulation which has no parent module!!!</span>
<a name="l00082"></a>00082             <span class="keywordflow">while</span> (parent != NULL &amp;&amp; parent-&gt;getParentModule() != NULL)
<a name="l00083"></a>00083             {
<a name="l00084"></a>00084                 node = parent;
<a name="l00085"></a>00085                 parent = node-&gt;getParentModule();
<a name="l00086"></a>00086             }
<a name="l00087"></a>00087             <span class="keywordflow">return</span> node;
<a name="l00088"></a>00088         }
<a name="l00089"></a>00089         <span class="keyword">static</span> <span class="keyword">const</span> cModule* findNetwork(<span class="keyword">const</span> cModule * <span class="keyword">const</span> m)
<a name="l00090"></a>00090         {
<a name="l00091"></a>00091             <span class="keyword">const</span> cModule* node = <a class="code" href="a00093.html#af74cf61bdeba8f88de8936dc32fc19ae" title="Returns a pointer to the host module of the passed module.">findHost</a>(m);
<a name="l00092"></a>00092 
<a name="l00093"></a>00093             <span class="keywordflow">return</span> node ? node-&gt;getParentModule() : node;
<a name="l00094"></a>00094         }
<a name="l00095"></a>00095 };
<a name="l00096"></a>00096 
<a name="l00101"></a>00101 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T = cModule&gt;
<a name="l00102"></a><a class="code" href="a00002.html">00102</a> <span class="keyword">class </span><a class="code" href="a00002.html" title="Finds and returns the pointer to a module of type T. Uses FindModule&lt;&gt;::findSubModule(), FindModule&lt;&gt;::findHost(). See usage e.g. at ConnectionManagerAccess.">AccessModuleWrap</a>
<a name="l00103"></a>00103 {
<a name="l00104"></a>00104     <span class="keyword">public</span>:
<a name="l00105"></a>00105         <span class="keyword">typedef</span> T wrapType;
<a name="l00106"></a>00106     <span class="keyword">private</span>:
<a name="l00107"></a>00107         T* pModule;
<a name="l00110"></a>00110         <a class="code" href="a00002.html" title="Finds and returns the pointer to a module of type T. Uses FindModule&lt;&gt;::findSubModule(), FindModule&lt;&gt;::findHost(). See usage e.g. at ConnectionManagerAccess.">AccessModuleWrap</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="Finds and returns the pointer to a module of type T. Uses FindModule&lt;&gt;::findSubModule(), FindModule&lt;&gt;::findHost(). See usage e.g. at ConnectionManagerAccess.">AccessModuleWrap&lt;T&gt;</a>&amp;);
<a name="l00113"></a>00113         <a class="code" href="a00002.html" title="Finds and returns the pointer to a module of type T. Uses FindModule&lt;&gt;::findSubModule(), FindModule&lt;&gt;::findHost(). See usage e.g. at ConnectionManagerAccess.">AccessModuleWrap&lt;T&gt;</a>&amp; <a class="code" href="a00002.html#a3c1a92bece36b793df6bdb3a44e35023" title="Assignment operator is not allowed.">operator=</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="Finds and returns the pointer to a module of type T. Uses FindModule&lt;&gt;::findSubModule(), FindModule&lt;&gt;::findHost(). See usage e.g. at ConnectionManagerAccess.">AccessModuleWrap&lt;T&gt;</a>&amp;);
<a name="l00114"></a>00114 
<a name="l00115"></a>00115     <span class="keyword">public</span>:
<a name="l00116"></a>00116         <a class="code" href="a00002.html" title="Finds and returns the pointer to a module of type T. Uses FindModule&lt;&gt;::findSubModule(), FindModule&lt;&gt;::findHost(). See usage e.g. at ConnectionManagerAccess.">AccessModuleWrap</a>() :
<a name="l00117"></a>00117                 pModule(NULL)
<a name="l00118"></a>00118         {
<a name="l00119"></a>00119         }
<a name="l00120"></a>00120 
<a name="l00121"></a>00121         <span class="keyword">virtual</span> ~<a class="code" href="a00002.html" title="Finds and returns the pointer to a module of type T. Uses FindModule&lt;&gt;::findSubModule(), FindModule&lt;&gt;::findHost(). See usage e.g. at ConnectionManagerAccess.">AccessModuleWrap</a>()
<a name="l00122"></a>00122         {
<a name="l00123"></a>00123         }
<a name="l00124"></a>00124         ;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         T* <span class="keyword">get</span>(cModule * <span class="keyword">const</span> from = NULL)
<a name="l00127"></a>00127         {
<a name="l00128"></a>00128             <span class="keywordflow">if</span> (!pModule)
<a name="l00129"></a>00129             {
<a name="l00130"></a>00130                 pModule = <a class="code" href="a00093.html" title="Provides method templates to find omnet modules.">FindModule&lt;T*&gt;::findSubModule</a>(
<a name="l00131"></a>00131                         <a class="code" href="a00093.html" title="Provides method templates to find omnet modules.">FindModule&lt;&gt;::findHost</a>(from != NULL ? from : simulation.getContextModule()));
<a name="l00132"></a>00132             }
<a name="l00133"></a>00133             <span class="keywordflow">return</span> pModule;
<a name="l00134"></a>00134         }
<a name="l00135"></a>00135 };
<a name="l00136"></a>00136 
<a name="l00137"></a>00137 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>FindModule.h</b>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:30 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
